package api

import (
	auto "beergo/app/com/auto/controller"
	"beergo/app/com/conf"
	"beergo/app/com/models"
	"beergo/conf/const/code"
	"beergo/lib/tool"
	"github.com/beego/beego/v2/server/web"
)

type ComConfigAdminController struct {
	auto.ComConfigController
}

func init() {
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/:id", 		&ComConfigAdminController{}, "*:GetAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/info", 		&ComConfigAdminController{}, "*:InfoAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/scan", 		&ComConfigAdminController{}, "*:ScanAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/list", 	    &ComConfigAdminController{}, "*:ListAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/update", 	&ComConfigAdminController{}, "*:UpdateAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/create", 	&ComConfigAdminController{}, "*:CreateAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/copy", 	    &ComConfigAdminController{}, "*:CopyAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/edit", 	    &ComConfigAdminController{}, "*:EditAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/delete", 	&ComConfigAdminController{}, "*:DeleteAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/:id/:field", &ComConfigAdminController{}, "*:SonsAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/choice", &ComConfigAdminController{}, "*:ChoiceAction")
	web.Router(conf.UrlPrefixAdmin + "/ComConfig/category", &ComConfigAdminController{}, "*:CategoryAction")

	web.Router(conf.UrlPrefix + "/ComConfig/v", &ComConfigAdminController{}, "*:GetValueAction")
}
//func (this *ComConfigAdminController) Prepare() {}
//func (this *ComConfigAdminController) ListAction() {}
//func (this *ComConfigAdminController) GetAction() {}
//func (this *ComConfigAdminController) InfoAction() {}
//func (this *ComConfigAdminController) ScanAction() {}
//func (this *ComConfigAdminController) CreateAction() {}
//func (this *ComConfigAdminController) UpdateAction() {}
//func (this *ComConfigAdminController) CopyAction() {}
//func (this *ComConfigAdminController) DeleteAction() {}
//func (this *ComConfigAdminController) EditAction() {}
//func (this *ComConfigAdminController) SonsAction() {}
//func (this *ComConfigAdminController) ChoiceAction() {}
//func (this *ComConfigAdminController) CategoryAction() {}


func (this *ComConfigAdminController) GetValueAction() {
	key:=this.GetParamString("key")
	rep:=models.ComConfigRepository{}
	find:=rep.FindOneBy(tool.M{"k":key},nil)
	if find.Id == 0 {
		this.ReturnSuccess("Not found","Not found")
		this.StopRun()
	}
	if find.T == nil {
		this.ReturnSuccess("T Not found","T Not found")
		this.StopRun()
	}
	switch find.T.Id {
	case 1:
		this.ReturnSuccess(find.Name,find.V)
		this.StopRun()
	case 2:
		this.ReturnSuccess(find.Name,find.Pic)
		this.StopRun()
	case 3:
		m:=find.Scan("",1,"")
		this.ReturnSuccess(find.Name,m["pics"])
		this.StopRun()
	case 4:
		m:=find.Scan("",1,"")
		this.ReturnSuccess(find.Name,m["files"])
		this.StopRun()
	case 5:
		this.ReturnSuccess(find.Name,find.Art)
		this.StopRun()
	}
	this.ReturnError(code.Error,"未知错误","")
}
